home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 2002 Tom Parker (tom@carrott.org),
- Matthias Münch (matthias@amigaworld.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- In addition, as a special exception, Tom Parker and Matthias Münch give
- permission to link the code of this program with a TCP stack of your
- choice, any official MUI libraries or classes and any custom MUI classes
- that should be necessary for the operation of this program. This
- exception also gives you permission to distribute linked combinations
- including this software with any of the before-mentioned libraries and
- classes. You must obey the GNU General Public License in all respects for
- all of the code used other than that provided by the before-mentioned
- libraries and classes. As part of this exception you are obliged to
- follow the license terms of the before-mentioned libraries, this license
- does not compel you to follow those terms, but if you do not then you may
- not link with those libraries. If you modify this file, you may extend
- this exception to your version of the file, but you are not obligated to
- do so. If you do not wish to do so, delete this exception statement from
- your version.
- */
- /*
- ** one-on-one chat window
- */
-
- #include "common.h"
- #include "edit.h"
-
- static ULONG chat_new(struct IClass *cl, Object *obj, struct opSet *msg);
- static void chat_send(Object *obj, struct chatdata *data);
-
-
- MUI_DISPATCH(chat_dispatch)
- {
- switch(msg->MethodID)
- {
- case OM_NEW:
- return chat_new(cl,obj,(APTR)msg);
-
- case CHAT_MSG:
- {
- struct chatdata *data = INST_DATA(cl,obj);
- ikspak *pak = (ikspak *)MARG1;
- DoMethod(data->list, CHATAREA_ADD, 0, "<<", iks_find_cdata(pak->x, "body"));
- return 0;
- }
-
- case CHAT_FLUSH:
- {
- struct chatdata *data = INST_DATA(cl,obj);
- DoMethod(data->list, CHATAREA_FLUSH);
- return 0;
- }
-
- case CHAT_SEND:
- chat_send(obj, INST_DATA(cl,obj));
- return 0;
-
- }
- return DoSuperMethodA(cl,obj,msg);
- }
-
-
- static ULONG chat_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- struct chatdata *data;
- Object *txt, *list, *str, *clrbut;
- juser u;
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_Window_Title, "Chat",
- MUIA_HelpNode, "window-chat",
- WindowContents, VGroup,
- Child, (ULONG) txt = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- MUIA_Text_PreParse, "\33c",
- End,
- Child, HGroup,
- Child, (ULONG) clrbut = SimpleButton(MSG_CHAT_FLUSH_GAD),
- Child, SimpleButton(MSG_CHAT_SAVE_GAD),
- Child, SimpleButton(MSG_CHAT_SEND_GAD),
- End,
- Child, list = NewObject(gui.chatarea_mcc->mcc_Class, NULL, TAG_DONE),
- Child, str = NewObject(gui.edit_mcc->mcc_Class, NULL,
- EDIT_TYPE, EDIT_TYPE_CHAT,
- MUIA_CycleChain, 1,
- TAG_DONE),
- End,
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(0);
-
- set(obj, MUIA_Window_DefaultObject, (ULONG) str);
- set(obj, MUIA_Window_ActiveObject, (ULONG) str);
-
- u = (juser)GetTagData(CHAT_WITH, NULL, msg->ops_AttrList);
- if(u->name)
- set(txt, MUIA_Text_Contents, (ULONG) my_printf("%s (%s)", u->name, convert_locale(iks_id_print(u->id))));
- else
- set(txt, MUIA_Text_Contents, (ULONG) convert_locale(iks_id_print(u->id)));
-
- set(obj, MUIA_Window_ActiveObject, (ULONG) str);
-
- data = INST_DATA(cl,obj);
- data->user = u;
- data->list = list;
- data->str = str;
-
-
- DoMethod(clrbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, CHAT_FLUSH);
-
- DoMethod(str, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, obj, 1, CHAT_SEND);
- DoMethod(obj, MUIM_Notify, MUIA_Window_Activate, TRUE, obj, 3, MUIM_Set, MUIA_Window_ActiveObject, str);
-
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj, 3, MUIM_Set, MUIA_Window_Open, FALSE);
-
- return((ULONG)obj);
- }
-
-
- static void chat_send(Object *obj, struct chatdata *data)
- {
- char *tmp, *jid;
- iks *x;
-
- tmp = mui_sget(data->str);
-
- if(!tmp) return;
-
- DoMethod(data->list, CHATAREA_ADD, 1, ">>", convert_utf8(tmp));
-
- x = iks_make_msg(IKS_TYPE_CHAT, iks_id_print(data->user->id), convert_utf8(tmp), NULL);
- iks_send(net.parser, x);
- iks_delete(x);
-
- set(data->str, MUIA_String_Contents, NULL);
- }
-
-
- void chat_with(juser u)
- {
- Object *win;
-
- if(u->chatwin)
- {
- set(u->chatwin, MUIA_Window_Open, TRUE);
- return;
- }
-
- win = NewObject(gui.chat_mcc->mcc_Class, NULL, CHAT_WITH, (ULONG) u, TAG_DONE);
- if(win)
- {
- DoMethod(gui.app, OM_ADDMEMBER, win);
- set(win, MUIA_Window_Open, TRUE);
- u->chatwin = win;
- }
- }
-
-
- int chat_packet(ikspak *pak)
- {
- juser u;
-
- u = roster_locate(pak->from);
-
- if(!u->chatwin)
- chat_with(u);
- else
- {
- u_long t;
- get(u->chatwin, MUIA_Window_Open, &t);
- if(t == FALSE) set(u->chatwin, MUIA_Window_Open, TRUE);
- }
-
- DoMethod(u->chatwin, CHAT_MSG, pak);
-
- return 1;
- }
-